odhcpd: rename dhcpv6_lease->clid[_data|_len]
authorDavid Härdeman <[email protected]>
Mon, 10 Nov 2025 22:19:31 +0000 (23:19 +0100)
committerÁlvaro Fernández Rojas <[email protected]>
Fri, 14 Nov 2025 16:25:27 +0000 (17:25 +0100)
The option is called clientid, but the option carries a DUID. So what
we're storing is a DUID, not a CLID.

Signed-off-by: David Härdeman <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/306
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/dhcpv6-ia.c
src/odhcpd.h
src/statefiles.c
src/ubus.c

index 3af3e42954e21c55c5c20ea6a219dc3c59d3c9ec..209c367c8ab628b68f36ba67e1047e49defefa66 100644 (file)
@@ -176,7 +176,7 @@ static int send_reconf(struct dhcpv6_lease *assign)
                uint8_t data[DUID_MAX_LEN];
        } _packed clientid = {
                .code = htons(DHCPV6_OPT_CLIENTID),
-               .len = htons(assign->clid_len),
+               .len = htons(assign->duid_len),
                .data = { 0 },
        };
        struct {
@@ -209,7 +209,7 @@ static int send_reconf(struct dhcpv6_lease *assign)
                serverid.len = htons(sizeof(duid_ll_hdr) + ETH_ALEN);
        }
 
-       memcpy(clientid.data, assign->clid_data, assign->clid_len);
+       memcpy(clientid.data, assign->duid, assign->duid_len);
 
        struct iovec iov[IOV_TOTAL] = {
                [IOV_HDR] = { &hdr, sizeof(hdr) },
@@ -426,8 +426,8 @@ static bool assign_na(struct interface *iface, struct dhcpv6_lease *a)
 
        /* Pick a starting point, using the last bytes of the DUID as seed... */
        memcpy(xsubi,
-              a->clid_data + (a->clid_len > sizeof(xsubi) ? a->clid_len - sizeof(xsubi) : 0),
-              min(a->clid_len, sizeof(xsubi)));
+              a->duid + (a->duid_len > sizeof(xsubi) ? a->duid_len - sizeof(xsubi) : 0),
+              min(a->duid_len, sizeof(xsubi)));
        try = ((uint64_t)jrand48(xsubi) << 32) | (jrand48(xsubi) & UINT32_MAX);
        try = pool_start + try % pool_size;
 
@@ -473,8 +473,8 @@ static void handle_addrlist_change(struct netevent_handler_info *info)
        set_border_assignment_size(iface, border);
 
        list_for_each_entry_safe(c, d, &iface->ia_assignments, head) {
-               if (c->clid_len == 0 ||
-                   !(c->flags & OAF_DHCPV6_PD) ||
+               if (c->duid_len == 0 ||
+                   !(c->flags & OAF_DHCPV6_PD) ||
                    (!INFINITE_VALID(c->valid_until) && c->valid_until < now))
                        continue;
 
@@ -490,8 +490,8 @@ static void handle_addrlist_change(struct netevent_handler_info *info)
 
                        /* Leave all other assignments of that client alone */
                        list_for_each_entry(a, &iface->ia_assignments, head)
-                               if (a != c && a->clid_len == c->clid_len &&
-                                               !memcmp(a->clid_data, c->clid_data, a->clid_len))
+                               if (a != c && a->duid_len == c->duid_len &&
+                                               !memcmp(a->duid, c->duid, a->duid_len))
                                        a->fr_cnt = INT_MAX;
                }
        }
@@ -548,7 +548,7 @@ static void valid_until_cb(struct uloop_timeout *event)
                        continue;
 
                list_for_each_entry_safe(a, n, &iface->ia_assignments, head) {
-                       if (a->clid_len > 0 && !INFINITE_VALID(a->valid_until) && a->valid_until < now)
+                       if (a->duid_len > 0 && !INFINITE_VALID(a->valid_until) && a->valid_until < now)
                                dhcpv6_free_lease(a);
                }
        }
@@ -942,17 +942,17 @@ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *ifac
        struct dhcpv6_lease *first = NULL;
        const struct dhcpv6_client_header *hdr = data;
        time_t now = odhcpd_time();
-       uint16_t otype, olen, clid_len = 0;
+       uint16_t otype, olen, duid_len = 0;
        uint8_t *start = (uint8_t *)&hdr[1], *odata;
-       uint8_t *clid_data = NULL, mac[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+       uint8_t *duid = NULL, mac[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
        size_t hostname_len = 0, response_len = 0;
        bool notonlink = false, rapid_commit = false, accept_reconf = false;
        char duidbuf[DUID_HEXSTRLEN], hostname[256];
 
        dhcpv6_for_each_option(start, end, otype, olen, odata) {
                if (otype == DHCPV6_OPT_CLIENTID) {
-                       clid_data = odata;
-                       clid_len = olen;
+                       duid = odata;
+                       duid_len = olen;
 
                        if (olen == 14 && odata[0] == 0 && odata[1] == 1)
                                memcpy(mac, &odata[8], sizeof(mac));
@@ -974,7 +974,7 @@ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *ifac
                        rapid_commit = true;
        }
 
-       if (!clid_data || !clid_len || clid_len > DUID_MAX_LEN)
+       if (!duid || duid_len < DUID_MIN_LEN || duid_len > DUID_MAX_LEN)
                goto out;
 
        dhcpv6_for_each_option(start, end, otype, olen, odata) {
@@ -990,7 +990,7 @@ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *ifac
                uint32_t reqhint = 0;
                struct lease_cfg *lease_cfg;
 
-               lease_cfg = config_find_lease_cfg_by_duid_and_iaid(clid_data, clid_len, ntohl(ia->iaid));
+               lease_cfg = config_find_lease_cfg_by_duid_and_iaid(duid, duid_len, ntohl(ia->iaid));
                if (!lease_cfg)
                        lease_cfg = config_find_lease_cfg_by_mac(mac);
 
@@ -1068,8 +1068,8 @@ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *ifac
                                continue;
 
                        /* Does the DUID match? */
-                       if (c->clid_len != clid_len || memcmp(c->clid_data, clid_data, clid_len))
-                               continue;
+                       if (c->duid_len != duid_len || memcmp(c->duid, duid, duid_len))
+                              continue;
 
                        /* Does the IAID match? */
                        if (c->iaid != ia->iaid) {
@@ -1092,10 +1092,10 @@ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *ifac
                                        if (lease_cfg->duids[i].iaid_set && lease_cfg->duids[i].iaid != htonl(ia->iaid))
                                                continue;
 
-                                       if (lease_cfg->duids[i].len != clid_len)
+                                       if (lease_cfg->duids[i].len != duid_len)
                                                continue;
 
-                                       if (memcmp(lease_cfg->duids[i].id, clid_data, clid_len))
+                                       if (memcmp(lease_cfg->duids[i].id, duid, duid_len))
                                                continue;
 
                                        /*
@@ -1138,11 +1138,11 @@ proceed:
                                if ((!iface->no_dynamic_dhcp || (lease_cfg && is_na)) &&
                                    (iface->dhcpv6_pd || iface->dhcpv6_na)) {
                                        /* Create new binding */
-                                       a = dhcpv6_alloc_lease(clid_len);
+                                       a = dhcpv6_alloc_lease(duid_len);
 
                                        if (a) {
-                                               a->clid_len = clid_len;
-                                               memcpy(a->clid_data, clid_data, clid_len);
+                                               a->duid_len = duid_len;
+                                               memcpy(a->duid, duid, duid_len);
                                                a->iaid = ia->iaid;
                                                a->length = reqlen;
                                                a->peer = *addr;
@@ -1275,7 +1275,7 @@ proceed:
                                a->flags &= ~OAF_BOUND;
 
                                if (!(a->flags & OAF_STATIC) || a->lease_cfg->hostid != a->assigned_host_id) {
-                                       memset(a->clid_data, 0, a->clid_len);
+                                       memset(a->duid, 0, a->duid_len);
                                        a->valid_until = now + 3600; /* Block address for 1h */
                                } else
                                        a->valid_until = now - 1;
index fbbba1adefa400f9c2f1130b70f42ca5eab1c5ca..d9860804d6f709eeddb3a52e7675bbdcab6c8483 100644 (file)
@@ -278,15 +278,15 @@ struct dhcpv6_lease {
                uint64_t assigned_host_id;
                uint32_t assigned_subnet_id;
        };
-       uint32_t iaid;
        uint8_t length; // length == 128 -> IA_NA, length <= 64 -> IA_PD
 
        unsigned int flags;
        uint32_t leasetime;
        char *hostname;
 
-       uint16_t clid_len;
-       uint8_t clid_data[];
+       uint32_t iaid;
+       uint16_t duid_len;
+       uint8_t duid[];
 };
 
 /* This corresponds to a UCI host section, i.e. a static lease cfg */
index 4258cbfde21d572ff731f29895905769b47a8c76..65920d25be8e9c355bd7234d3795a61c012f3ccf 100644 (file)
@@ -192,7 +192,7 @@ static void statefiles_write_state6(struct write_ctxt *ctxt, struct dhcpv6_lease
        if (!ctxt->fp)
                return;
 
-       odhcpd_hexlify(duidbuf, lease->clid_data, lease->clid_len);
+       odhcpd_hexlify(duidbuf, lease->duid, lease->duid_len);
 
        /* # <iface> <hexduid> <hexiaid> <hostname> <valid_until> <assigned_[host|subnet]_id> <pfx_length> [<addrs> ...] */
        fprintf(ctxt->fp,
index 51c47083c158e0e7522016fb2604ab79fed4cbd4..ca15d37b6622c2bf4cafc6cdd391d30f0d640056 100644 (file)
@@ -130,9 +130,9 @@ static int handle_dhcpv6_leases(_unused struct ubus_context *ctx, _unused struct
                                continue;
 
                        void *m, *l = blobmsg_open_table(&b, NULL);
-                       char *buf = blobmsg_alloc_string_buffer(&b, "duid", 264);
+                       char *buf = blobmsg_alloc_string_buffer(&b, "duid", DUID_HEXSTRLEN);
 
-                       odhcpd_hexlify(buf, a->clid_data, a->clid_len);
+                       odhcpd_hexlify(buf, a->duid, a->duid_len);
                        blobmsg_add_string_buffer(&b);
 
                        blobmsg_add_u32(&b, "iaid", ntohl(a->iaid));